package parts1.lesson30;

import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.datasource.DriverManagerDataSource;

import java.sql.Connection;
import java.sql.SQLException;

public class DemoJdbcTemplate {
    public static void main(String[] args) throws SQLException {
        String url="jdbc:mysql://localhost:3306/springdb";
        String username="root";
        String password="root";
        DriverManagerDataSource source=new DriverManagerDataSource(url,username,password);
        source.setDriverClassName("com.mysql.jdbc.Driver");
        Connection conn=source.getConnection();
        System.out.println(conn);

        JdbcTemplate jt=new JdbcTemplate(source);
        String sql="INSERT INTO `news` (`title`,`time`,`content`) VALUE (?,?,?)";
        int count=jt.update(sql,"新闻标题","2019-01-19","我这里随便打点内容");
        System.out.println("update num:"+count);
        source.getConnection().close();

    }
}
